package com.hushao.aimi.controller;



import com.hushao.aimi.common.ServerResponse;

import com.hushao.aimi.vo.UserVo;
import com.hushao.aimi.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @description: 用户控制器
 * @author: 胡少
 * @create: 2018-06-03 21:46
 **/
@RestController
@RequestMapping("/u")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 账号注册
     * @param user
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "注册")
    @PostMapping
    public ServerResponse register(@RequestBody UserVo user)throws Exception{
        return userService.register(user);
    }


    /**
     * 个人信息获取
     * @param username
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取个人信息")
    @GetMapping("/{username}")
    public ServerResponse getUserInfo(@PathVariable("username")String username)throws Exception{
       return userService.getUserInfo(username);
    }


    /**
     * 验证
     * @param username
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取个人信息")
    @GetMapping("/valid")
    public ServerResponse getUserInfo(@RequestParam(value = "username",required = false)String username,
                                      @RequestParam(value = "phone",required = false)String phone)throws Exception{
        return userService.valid(username,phone);
    }

}
